package com.lin.gram.controller.graphController;

import com.lin.gram.pojo.graphPojo.CustomNode;
import com.lin.gram.pojo.graphPojo.Inventor;
import com.lin.gram.pojo.graphPojo.Patent;
import com.lin.gram.pojo.graphPojo.QuerySizer;
import com.lin.gram.service.graphService.InventorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

/**为了节点的多级扩散，InventorController需仿造PatentController写，映射url不一样
 *
 * @author ChenweiLin
 * @create 2021-05-03 14:14
 */
@RestController
@RequestMapping("/api/inventor")
public class InventorController {
    @Autowired
    InventorService inventorService;

//    @GetMapping("/{name}")
//    public Inventor findByName(@PathVariable("name") String name){
//        Inventor inventor = inventorService.findByName(name);
//        System.out.println(inventor.toString());
//        return inventor;
//    }

    @PostMapping("/test")
    public Inventor findByName(@RequestBody Inventor inventor){
        String name = inventor.getName();

        Inventor it = inventorService.findByName(name);
        String string = it.toString();

        return it;
    }

    @PostMapping("/belongto")
    public List<CustomNode> createdInventor(@RequestBody QuerySizer querySizer){
        System.out.println("这是InventorController");
        System.out.println(querySizer.toString());

        List<CustomNode> customNodes = new ArrayList<>();
        String inventorName = querySizer.getCurrentNodeNum();

        Inventor in = inventorService.findByName(inventorName);

        Set<Patent> patentsSet = in.getCreatedPatents();
        for (Patent patent : patentsSet) {
            customNodes.add(new CustomNode(patent.getName(),1,patent));
        }
        return customNodes;
    }
}
